knitr::opts_chunk$set(fig.width = 8,fig.height = 6)
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.3.6 ✔ purrr 0.3.5
## ✔ tibble 3.1.8 ✔ dplyr 1.0.10
## ✔ tidyr 1.2.1 ✔ stringr 1.4.1
## ✔ readr 2.1.3 ✔ forcats 0.5.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
library(rayshader)
library(patchwork)
library(skimr)
library(visdat)
library(ggplot2)
library(GGally)
## Registered S3 method overwritten by 'GGally':
## method from
## +.gg ggplot2
library(corrplot)
## corrplot 0.92 loaded
D = read.table("/Users/macbook/Documents/Bayesian Statistics/Project/Raw_data/LIPIDI/78 variabili/101_lipidi-PreProcessed-IM-Step1-Step2-Step4-Step5-101.txt")
sum(is.na(D))
## [1] 634087
the numbers of na is substantial
vis_miss(D,warn_large_data = FALSE)
## Warning: `gather_()` was deprecated in tidyr 1.2.0.
## ℹ Please use `gather()` instead.
## ℹ The deprecated feature was likely used in the visdat package.
## Please report the issue at <]8;;https://github.com/ropensci/visdat/issueshttps://github.com/ropensci/visdat/issues]8;;>.
the missing data is about 45%
skim(D)
| Name | D |
| Number of rows | 18229 |
| Number of columns | 78 |
| _______________________ | |
| Column type frequency: | |
| numeric | 78 |
| ________________________ | |
| Group variables | None |
Variable type: numeric
| skim_variable | n_missing | complete_rate | mean | sd | p0 | p25 | p50 | p75 | p100 | hist |
|---|---|---|---|---|---|---|---|---|---|---|
| X401.18155749152 | 1561 | 0.91 | 0.14 | 0.07 | 0.02 | 0.09 | 0.13 | 0.18 | 0.81 | ▇▂▁▁▁ |
| X402.175372221284 | 4352 | 0.76 | 0.09 | 0.04 | 0.02 | 0.06 | 0.08 | 0.11 | 0.38 | ▇▅▁▁▁ |
| X409.217742652953 | 4174 | 0.77 | 0.10 | 0.11 | 0.03 | 0.06 | 0.07 | 0.10 | 1.34 | ▇▁▁▁▁ |
| X419.246407498537 | 12919 | 0.29 | 0.06 | 0.01 | 0.02 | 0.05 | 0.05 | 0.06 | 0.14 | ▃▇▂▁▁ |
| X426.123469726227 | 4124 | 0.77 | 0.13 | 0.07 | 0.03 | 0.09 | 0.12 | 0.15 | 1.25 | ▇▁▁▁▁ |
| X437.311179462526 | 9143 | 0.50 | 0.13 | 0.05 | 0.04 | 0.10 | 0.12 | 0.15 | 0.52 | ▇▃▁▁▁ |
| X442.117407247144 | 8813 | 0.52 | 0.22 | 0.13 | 0.03 | 0.14 | 0.18 | 0.26 | 1.37 | ▇▂▁▁▁ |
| X447.212994469759 | 542 | 0.97 | 0.62 | 0.24 | 0.01 | 0.45 | 0.60 | 0.77 | 2.14 | ▃▇▂▁▁ |
| X448.206629110332 | 11103 | 0.39 | 0.11 | 0.03 | 0.03 | 0.08 | 0.10 | 0.12 | 0.38 | ▇▇▁▁▁ |
| X449.181170853303 | 11116 | 0.39 | 0.11 | 0.04 | 0.02 | 0.08 | 0.10 | 0.13 | 0.49 | ▇▅▁▁▁ |
| X465.221110403551 | 9453 | 0.48 | 0.05 | 0.02 | 0.02 | 0.04 | 0.04 | 0.05 | 0.25 | ▇▁▁▁▁ |
| X478.277226797819 | 4972 | 0.73 | 0.06 | 0.02 | 0.01 | 0.05 | 0.06 | 0.07 | 0.15 | ▁▇▅▁▁ |
| X479.248654523272 | 12046 | 0.34 | 0.04 | 0.02 | 0.02 | 0.03 | 0.04 | 0.05 | 0.32 | ▇▁▁▁▁ |
| X497.206369201144 | 10686 | 0.41 | 0.07 | 0.22 | 0.02 | 0.05 | 0.06 | 0.07 | 9.15 | ▇▁▁▁▁ |
| X506.28595502602 | 13991 | 0.23 | 0.05 | 0.01 | 0.01 | 0.04 | 0.05 | 0.06 | 0.14 | ▂▇▂▁▁ |
| X511.153597066032 | 11218 | 0.38 | 0.52 | 1.12 | 0.01 | 0.04 | 0.05 | 0.24 | 11.68 | ▇▁▁▁▁ |
| X513.237647290215 | 14480 | 0.21 | 0.08 | 0.06 | 0.01 | 0.04 | 0.06 | 0.09 | 0.77 | ▇▁▁▁▁ |
| X524.279211549971 | 4709 | 0.74 | 0.10 | 0.03 | 0.02 | 0.08 | 0.09 | 0.12 | 0.30 | ▂▇▂▁▁ |
| X525.261547813485 | 12627 | 0.31 | 0.05 | 0.01 | 0.01 | 0.04 | 0.05 | 0.06 | 0.12 | ▁▇▃▁▁ |
| X538.265072270527 | 9789 | 0.46 | 0.05 | 0.01 | 0.02 | 0.04 | 0.05 | 0.05 | 0.10 | ▂▇▅▁▁ |
| X552.2715207686 | 10676 | 0.41 | 0.06 | 0.01 | 0.01 | 0.05 | 0.06 | 0.06 | 0.12 | ▁▇▇▁▁ |
| X553.239346145671 | 2177 | 0.88 | 0.19 | 0.09 | 0.01 | 0.13 | 0.18 | 0.24 | 0.69 | ▅▇▂▁▁ |
| X558.153387011278 | 14329 | 0.21 | 0.06 | 0.02 | 0.02 | 0.05 | 0.05 | 0.07 | 0.26 | ▇▂▁▁▁ |
| X566.28121499168 | 14220 | 0.22 | 0.08 | 0.02 | 0.02 | 0.06 | 0.08 | 0.09 | 0.17 | ▁▇▆▁▁ |
| X568.285314369757 | 9344 | 0.49 | 0.16 | 0.05 | 0.02 | 0.12 | 0.15 | 0.19 | 0.42 | ▂▇▃▁▁ |
| X576.257761688406 | 10669 | 0.41 | 0.06 | 0.02 | 0.02 | 0.04 | 0.05 | 0.06 | 0.23 | ▇▅▁▁▁ |
| X577.277943537651 | 9942 | 0.45 | 0.12 | 0.05 | 0.03 | 0.09 | 0.11 | 0.14 | 0.52 | ▇▅▁▁▁ |
| X578.280306512124 | 10705 | 0.41 | 0.07 | 0.03 | 0.02 | 0.06 | 0.07 | 0.09 | 0.29 | ▇▅▁▁▁ |
| X592.267287982367 | 12440 | 0.32 | 0.08 | 0.03 | 0.02 | 0.07 | 0.08 | 0.10 | 0.26 | ▆▇▁▁▁ |
| X595.24167872285 | 13615 | 0.25 | 0.08 | 0.02 | 0.03 | 0.07 | 0.08 | 0.09 | 0.16 | ▁▇▆▁▁ |
| X599.312316651348 | 1947 | 0.89 | 0.15 | 0.06 | 0.02 | 0.11 | 0.14 | 0.17 | 0.92 | ▇▁▁▁▁ |
| X600.287990847865 | 9059 | 0.50 | 0.08 | 0.02 | 0.02 | 0.06 | 0.08 | 0.09 | 0.31 | ▇▇▁▁▁ |
| X614.280680723305 | 11990 | 0.34 | 0.06 | 0.02 | 0.02 | 0.05 | 0.06 | 0.07 | 0.22 | ▇▆▁▁▁ |
| X616.374126264944 | 13264 | 0.27 | 0.05 | 0.01 | 0.02 | 0.04 | 0.05 | 0.05 | 0.09 | ▁▇▇▂▁ |
| X652.361088301576 | 9561 | 0.48 | 0.08 | 0.03 | 0.02 | 0.06 | 0.08 | 0.10 | 0.21 | ▃▇▅▁▁ |
| X653.324143837042 | 2179 | 0.88 | 0.24 | 0.10 | 0.01 | 0.18 | 0.23 | 0.29 | 1.28 | ▇▃▁▁▁ |
| X654.321418202011 | 10592 | 0.42 | 0.14 | 0.04 | 0.02 | 0.11 | 0.14 | 0.17 | 0.35 | ▁▇▅▁▁ |
| X666.348091732679 | 10727 | 0.41 | 0.12 | 0.04 | 0.02 | 0.09 | 0.11 | 0.15 | 0.31 | ▂▇▅▁▁ |
| X668.350119384666 | 8434 | 0.54 | 0.09 | 0.04 | 0.02 | 0.06 | 0.08 | 0.11 | 0.26 | ▆▇▃▁▁ |
| X697.336385172531 | 765 | 0.96 | 0.28 | 0.10 | 0.02 | 0.22 | 0.28 | 0.35 | 0.63 | ▂▆▇▂▁ |
| X698.342468583488 | 6941 | 0.62 | 0.18 | 0.06 | 0.01 | 0.14 | 0.18 | 0.22 | 0.45 | ▂▇▇▁▁ |
| X713.313334386064 | 7293 | 0.60 | 0.21 | 0.09 | 0.02 | 0.16 | 0.21 | 0.25 | 1.06 | ▇▅▁▁▁ |
| X723.369767544851 | 9485 | 0.48 | 0.08 | 0.02 | 0.01 | 0.07 | 0.08 | 0.10 | 0.16 | ▁▅▇▃▁ |
| X724.357765223416 | 11747 | 0.36 | 0.06 | 0.02 | 0.01 | 0.04 | 0.06 | 0.07 | 0.17 | ▂▇▂▁▁ |
| X726.353588041765 | 10899 | 0.40 | 0.15 | 0.04 | 0.02 | 0.13 | 0.15 | 0.17 | 0.48 | ▁▇▁▁▁ |
| X737.153366400938 | 4088 | 0.78 | 0.14 | 0.07 | 0.01 | 0.09 | 0.13 | 0.17 | 0.73 | ▇▃▁▁▁ |
| X753.367749586126 | 8284 | 0.55 | 0.13 | 0.04 | 0.02 | 0.10 | 0.13 | 0.15 | 0.32 | ▂▇▆▁▁ |
| X762.346785523875 | 12992 | 0.29 | 0.08 | 0.02 | 0.02 | 0.06 | 0.08 | 0.09 | 0.20 | ▂▇▃▁▁ |
| X764.372631793774 | 11446 | 0.37 | 0.05 | 0.02 | 0.01 | 0.04 | 0.05 | 0.07 | 0.14 | ▃▇▃▁▁ |
| X774.982938560717 | 8359 | 0.54 | 0.19 | 0.06 | 0.02 | 0.15 | 0.19 | 0.23 | 0.53 | ▁▇▃▁▁ |
| X775.976648338383 | 13999 | 0.23 | 0.08 | 0.02 | 0.02 | 0.06 | 0.08 | 0.09 | 0.17 | ▂▇▇▂▁ |
| X778.403735371109 | 9983 | 0.45 | 1.18 | 0.53 | 0.02 | 0.82 | 1.14 | 1.52 | 4.02 | ▃▇▂▁▁ |
| X779.39508853726 | 5855 | 0.68 | 0.50 | 0.26 | 0.01 | 0.29 | 0.46 | 0.68 | 1.83 | ▇▇▃▁▁ |
| X780.399514391103 | 8392 | 0.54 | 0.27 | 0.13 | 0.02 | 0.17 | 0.24 | 0.35 | 0.97 | ▇▇▃▁▁ |
| X793.327494359355 | 14448 | 0.21 | 0.08 | 0.03 | 0.01 | 0.06 | 0.08 | 0.10 | 0.17 | ▂▆▇▅▁ |
| X806.438265275953 | 1282 | 0.93 | 1.50 | 1.55 | 0.02 | 0.37 | 0.99 | 2.04 | 10.18 | ▇▂▁▁▁ |
| X807.430315603065 | 2270 | 0.88 | 0.93 | 0.81 | 0.01 | 0.27 | 0.70 | 1.37 | 4.61 | ▇▃▂▁▁ |
| X808.418052996172 | 4205 | 0.77 | 0.48 | 0.34 | 0.01 | 0.21 | 0.40 | 0.70 | 2.01 | ▇▅▂▁▁ |
| X822.416323513071 | 2717 | 0.85 | 1.34 | 0.84 | 0.02 | 0.64 | 1.25 | 1.92 | 5.52 | ▇▇▃▁▁ |
| X823.418850404014 | 3984 | 0.78 | 0.87 | 0.51 | 0.02 | 0.48 | 0.79 | 1.23 | 2.88 | ▇▇▅▁▁ |
| X836.412896788889 | 9507 | 0.48 | 0.22 | 0.09 | 0.01 | 0.15 | 0.20 | 0.28 | 0.62 | ▂▇▃▁▁ |
| X862.437600249503 | 280 | 0.98 | 2.79 | 2.42 | 0.01 | 0.66 | 2.24 | 4.31 | 13.04 | ▇▃▂▁▁ |
| X863.420550439 | 1936 | 0.89 | 1.53 | 1.15 | 0.01 | 0.54 | 1.31 | 2.31 | 6.36 | ▇▅▃▁▁ |
| X888.444482031706 | 1435 | 0.92 | 9.36 | 6.70 | 0.02 | 3.84 | 8.39 | 13.40 | 40.59 | ▇▆▂▁▁ |
| X889.43378336125 | 4013 | 0.78 | 5.00 | 3.82 | 0.03 | 2.09 | 4.21 | 7.08 | 22.78 | ▇▅▂▁▁ |
| X890.455559065043 | 1940 | 0.89 | 11.17 | 8.12 | 0.03 | 4.38 | 9.83 | 16.57 | 44.94 | ▇▆▃▁▁ |
| X904.460038847805 | 10652 | 0.42 | 2.05 | 1.79 | 0.03 | 0.37 | 1.77 | 3.24 | 9.68 | ▇▅▂▁▁ |
| X906.471649609416 | 673 | 0.96 | 12.42 | 9.56 | 0.02 | 4.10 | 11.08 | 18.50 | 51.34 | ▇▆▃▁▁ |
| X907.47494585213 | 8186 | 0.55 | 8.65 | 5.02 | 0.02 | 4.82 | 8.24 | 12.22 | 26.62 | ▆▇▆▂▁ |
| X908.485206763087 | 3471 | 0.81 | 3.38 | 2.22 | 0.01 | 1.68 | 3.06 | 4.85 | 12.40 | ▇▇▃▁▁ |
| X933.449659746903 | 11508 | 0.37 | 0.10 | 0.03 | 0.01 | 0.07 | 0.10 | 0.12 | 0.24 | ▂▇▆▁▁ |
| X934.487399616051 | 13583 | 0.25 | 0.28 | 0.12 | 0.01 | 0.20 | 0.27 | 0.36 | 0.77 | ▂▇▅▁▁ |
| X942.439351429176 | 13376 | 0.27 | 0.08 | 0.03 | 0.01 | 0.05 | 0.08 | 0.10 | 0.24 | ▅▇▃▁▁ |
| X943.432502731421 | 7473 | 0.59 | 0.10 | 0.04 | 0.01 | 0.07 | 0.09 | 0.12 | 0.32 | ▃▇▂▁▁ |
| X944.447551703558 | 10962 | 0.40 | 0.07 | 0.03 | 0.01 | 0.05 | 0.06 | 0.08 | 0.29 | ▇▅▁▁▁ |
| X965.462816974066 | 2475 | 0.86 | 0.10 | 0.04 | 0.01 | 0.07 | 0.09 | 0.12 | 0.33 | ▅▇▂▁▁ |
| X966.464009229031 | 6153 | 0.66 | 0.06 | 0.02 | 0.01 | 0.04 | 0.05 | 0.07 | 0.17 | ▅▇▂▁▁ |
| X967.456646158017 | 9342 | 0.49 | 0.04 | 0.01 | 0.01 | 0.03 | 0.04 | 0.05 | 0.10 | ▂▇▃▁▁ |
we observe that the missing data is not uniform in the mz, there are some values for which only 20 - 30% of the pixel have a value, and this tends to be small
we replace the missing data with 0 since it means the data for that mz was under threshold
D0 = D
D0[is.na(D0)] = 0
look at the distribution and correlation of the data, beginning with similar mz probably ggpairs is not the most efficient, did not change the labels
ggpairs(D,columns = 1:7)
ggpairs(D,columns = 8:14)
ggpairs(D,columns = 15:21)
ggpairs(D,columns = 16:28)
ggpairs(D,columns = 28:35)
ggpairs(D,columns = 36:42)
ggpairs(D,columns = 43:49)
ggpairs(D,columns = 50:56)
we see a lot of correlation in the data especially below
ggpairs(D,columns = 57:63)
ggpairs(D,columns = 64:70)
ggpairs(D,columns = 70:78)
do the zeros added contribute a lot to the correlation?
the peaks that we have around 800 mz are all correlated and are basically the same information
this high correlation explains the performance of pca
cm <- cor(D0)
corrplot(cm, method = "color")
the blue blob is the observation from above
pixels = read.table("/Users/macbook/Documents/Bayesian Statistics/Project/Raw_data/LIPIDI/78 variabili/101_lipidi-PreProcessed-XYCoordinates-Step1-Step2-Step4-Step5-101.txt")
colnames(D0) = substr(colnames(D0),1,4)
colnames(pixels) = c("x","y")
Create the datasets we will need:
Data_long: contains the 18k pixels on the rows. The
first two columns are the coordinates, the remaining 78 are the values
recorded for different m.z.
Data_array: contains a cube with the 78 slices on
the third dimension. Not all the pixels are recored in each rectangle:
beware of NA’s.
Data_long = as_tibble(data.frame( pixels, D0 ))
max_number_of_pixels = apply(Data_long[,1:2],2,max)
Data_array = matrix(NA,max_number_of_pixels[1],max_number_of_pixels[2])
Data_array = array(NA,c(max_number_of_pixels[1],max_number_of_pixels[2],ncol(D0)))
sum(is.na(D0))
## [1] 0
# there must be a better way to do this, but it's sunday morning, please be patient...
for(k in 1:ncol(D0)){
for(i in 1:nrow(Data_long)){
Data_array[Data_long$x[i],Data_long$y[i],k] = D0[i,k]
}
}
dim(Data_array)
## x y
## 157 178 78
Data_very_long = reshape2::melt(Data_long,c("x","y")) %>% mutate(pixel_ind = paste0(x,"_",y), value_ind = rep(1:nrow(Data_long),ncol(D0)))
Data_very_long = Data_very_long %>% group_by(pixel_ind) %>% mutate(n = row_number()) %>% ungroup() %>% mutate(mz = as.numeric(substr(variable,2,4)))
Data_very_long = reshape2::melt(Data_long,c("x","y")) %>% mutate(pixel_ind = paste0(x,"_",y), value_ind = rep(1:nrow(Data_long),ncol(D0)))
Data_very_long = Data_very_long %>% group_by(pixel_ind) %>% mutate(n = row_number()) %>% ungroup() %>% mutate(mz = as.numeric(substr(variable,2,4)))
# subsampling to get a faster plot and not drain memory
sub_ind = sample(unique(Data_very_long$pixel_ind),1000)
# just to get the gist:
ggplot(Data_very_long %>% filter(pixel_ind %in% sub_ind))+
geom_path(aes(x = mz, y = value,
col=pixel_ind,
group = pixel_ind),alpha=.5)+theme_bw()+theme(legend.position = "none")+xlab("m.z")+scale_color_viridis_d(option = "A")+
scale_x_continuous(n.breaks = 20)
the spike is in mz 511 on the edge
- possible problem of the instrument on the edge of the brain - outlier
? the rest is just noise
the spike is relative to 778 779 780
very similar to each other
this are all the same, it is the high correlated blob in the correlation matrix
the peak is in 906 907 908 which are very similar
the rest is not that itresting, very low values resamble kind on veramble the previuus structure but basically noise
pca = princomp(D0)
plot(pca)
summary(pca)
## Importance of components:
## Comp.1 Comp.2 Comp.3 Comp.4 Comp.5
## Standard deviation 16.063465 3.74669709 1.8050014 1.557047404 1.16570821
## Proportion of Variance 0.917156 0.04989556 0.0115803 0.008617244 0.00482997
## Cumulative Proportion 0.917156 0.96705159 0.9786319 0.987249138 0.99207911
## Comp.6 Comp.7 Comp.8 Comp.9
## Standard deviation 0.775473863 0.732621491 0.5247242544 0.4176023644
## Proportion of Variance 0.002137465 0.001907761 0.0009786491 0.0006198558
## Cumulative Proportion 0.994216573 0.996124335 0.9971029837 0.9977228394
## Comp.10 Comp.11 Comp.12 Comp.13
## Standard deviation 0.3441918928 0.3285733456 0.2614626699 0.2329424828
## Proportion of Variance 0.0004210814 0.0003837332 0.0002429876 0.0001928689
## Cumulative Proportion 0.9981439208 0.9985276540 0.9987706416 0.9989635105
## Comp.14 Comp.15 Comp.16 Comp.17
## Standard deviation 0.1901943823 0.1719970735 1.542005e-01 1.494558e-01
## Proportion of Variance 0.0001285761 0.0001051494 8.451544e-05 7.939449e-05
## Cumulative Proportion 0.9990920865 0.9991972360 9.992818e-01 9.993611e-01
## Comp.18 Comp.19 Comp.20 Comp.21
## Standard deviation 1.437853e-01 1.277647e-01 1.156808e-01 1.124762e-01
## Proportion of Variance 7.348417e-05 5.802117e-05 4.756501e-05 4.496621e-05
## Cumulative Proportion 9.994346e-01 9.994927e-01 9.995402e-01 9.995852e-01
## Comp.22 Comp.23 Comp.24 Comp.25
## Standard deviation 1.112338e-01 1.101552e-01 9.828352e-02 8.492948e-02
## Proportion of Variance 4.397825e-05 4.312951e-05 3.433414e-05 2.563786e-05
## Cumulative Proportion 9.996292e-01 9.996723e-01 9.997066e-01 9.997323e-01
## Comp.26 Comp.27 Comp.28 Comp.29
## Standard deviation 8.148553e-02 7.341267e-02 7.132058e-02 0.0693419808
## Proportion of Variance 2.360075e-05 1.915609e-05 1.807984e-05 0.0000170906
## Cumulative Proportion 9.997559e-01 9.997750e-01 9.997931e-01 0.9998101895
## Comp.30 Comp.31 Comp.32 Comp.33
## Standard deviation 6.664939e-02 6.041977e-02 0.0591444918 5.537155e-02
## Proportion of Variance 1.578909e-05 1.297546e-05 0.0000124335 1.089778e-05
## Cumulative Proportion 9.998260e-01 9.998390e-01 0.9998513875 9.998623e-01
## Comp.34 Comp.35 Comp.36 Comp.37
## Standard deviation 5.324759e-02 5.195975e-02 0.0500307473 4.844369e-02
## Proportion of Variance 1.007778e-05 9.596191e-06 0.0000088969 8.341404e-06
## Cumulative Proportion 9.998724e-01 9.998820e-01 0.9998908562 9.998992e-01
## Comp.38 Comp.39 Comp.40 Comp.41
## Standard deviation 4.698990e-02 4.254707e-02 3.900727e-02 3.613078e-02
## Proportion of Variance 7.848266e-06 6.434341e-06 5.408237e-06 4.640016e-06
## Cumulative Proportion 9.999070e-01 9.999135e-01 9.999189e-01 9.999235e-01
## Comp.42 Comp.43 Comp.44 Comp.45
## Standard deviation 3.413272e-02 3.298352e-02 3.136910e-02 3.051343e-02
## Proportion of Variance 4.141012e-06 3.866862e-06 3.497589e-06 3.309381e-06
## Cumulative Proportion 9.999277e-01 9.999315e-01 9.999350e-01 9.999383e-01
## Comp.46 Comp.47 Comp.48 Comp.49
## Standard deviation 2.993919e-02 2.931011e-02 2.866060e-02 2.810079e-02
## Proportion of Variance 3.185993e-06 3.053513e-06 2.919680e-06 2.806738e-06
## Cumulative Proportion 9.999415e-01 9.999446e-01 9.999475e-01 9.999503e-01
## Comp.50 Comp.51 Comp.52 Comp.53
## Standard deviation 2.706671e-02 2.659691e-02 2.635536e-02 2.555264e-02
## Proportion of Variance 2.603969e-06 2.514359e-06 2.468896e-06 2.320792e-06
## Cumulative Proportion 9.999529e-01 9.999554e-01 9.999579e-01 9.999602e-01
## Comp.54 Comp.55 Comp.56 Comp.57
## Standard deviation 2.524454e-02 2.487671e-02 2.455916e-02 2.438560e-02
## Proportion of Variance 2.265165e-06 2.199636e-06 2.143836e-06 2.113642e-06
## Cumulative Proportion 9.999625e-01 9.999647e-01 9.999668e-01 9.999689e-01
## Comp.58 Comp.59 Comp.60 Comp.61
## Standard deviation 2.377389e-02 2.311280e-02 2.300476e-02 2.231907e-02
## Proportion of Variance 2.008932e-06 1.898759e-06 1.881049e-06 1.770585e-06
## Cumulative Proportion 9.999709e-01 9.999728e-01 9.999747e-01 9.999765e-01
## Comp.62 Comp.63 Comp.64 Comp.65
## Standard deviation 2.215556e-02 2.197574e-02 2.183727e-02 2.111930e-02
## Proportion of Variance 1.744738e-06 1.716532e-06 1.694967e-06 1.585346e-06
## Cumulative Proportion 9.999782e-01 9.999800e-01 9.999817e-01 9.999832e-01
## Comp.66 Comp.67 Comp.68 Comp.69
## Standard deviation 2.065927e-02 2.060456e-02 2.037009e-02 1.987790e-02
## Proportion of Variance 1.517033e-06 1.509007e-06 1.474860e-06 1.404448e-06
## Cumulative Proportion 9.999848e-01 9.999863e-01 9.999877e-01 9.999891e-01
## Comp.70 Comp.71 Comp.72 Comp.73
## Standard deviation 1.939794e-02 1.925609e-02 1.916565e-02 1.876678e-02
## Proportion of Variance 1.337445e-06 1.317955e-06 1.305605e-06 1.251827e-06
## Cumulative Proportion 9.999905e-01 9.999918e-01 9.999931e-01 9.999944e-01
## Comp.74 Comp.75 Comp.76 Comp.77
## Standard deviation 1.863689e-02 1.821375e-02 1.753698e-02 1.738131e-02
## Proportion of Variance 1.234558e-06 1.179135e-06 1.093136e-06 1.073816e-06
## Cumulative Proportion 9.999956e-01 9.999968e-01 9.999979e-01 9.999989e-01
## Comp.78
## Standard deviation 1.727547e-02
## Proportion of Variance 1.060778e-06
## Cumulative Proportion 1.000000e+00
the pca works well because of the correlation
PCA1 = ggplot(Data_long %>% mutate(pca1 = pca$scores[,1]))+ theme_bw()+
geom_tile(aes(x=x,y=y,fill = pca1))+scale_fill_viridis_c(option = "A",na.value = "red")+
theme_void()+theme(legend.position = "bottom")
PCA2 = ggplot(Data_long %>% mutate(pca2 = pca$scores[,2]))+ theme_bw()+
geom_tile(aes(x=x,y=y,fill = pca2))+scale_fill_viridis_c(option = "A",na.value = "red")+
theme_void()+theme(legend.position = "bottom")
PCA1+PCA2
if we invert the colormap
PCA1v2 = ggplot(Data_long %>% mutate(pca1 = pca$scores[,1]))+ theme_bw()+
geom_tile(aes(x=x,y=y,fill = -1*pca1))+scale_fill_viridis_c(option = "A",na.value = "red")+
theme_void()+theme(legend.position = "bottom")
PCA1v2 + P6
the data is clearly dominated by this peaks that are highly correlated and spatially correlated as well
first component
second component
sessionInfo()
## R version 4.2.1 (2022-06-23)
## Platform: x86_64-apple-darwin17.0 (64-bit)
## Running under: macOS Big Sur ... 10.16
##
## Matrix products: default
## BLAS: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib
##
## locale:
## [1] it_IT.UTF-8/it_IT.UTF-8/it_IT.UTF-8/C/it_IT.UTF-8/it_IT.UTF-8
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] corrplot_0.92 GGally_2.1.2 visdat_0.5.3 skimr_2.1.4
## [5] patchwork_1.1.2 rayshader_0.24.10 forcats_0.5.2 stringr_1.4.1
## [9] dplyr_1.0.10 purrr_0.3.5 readr_2.1.3 tidyr_1.2.1
## [13] tibble_3.1.8 ggplot2_3.3.6 tidyverse_1.3.2
##
## loaded via a namespace (and not attached):
## [1] httr_1.4.4 sass_0.4.2 viridisLite_0.4.1
## [4] jsonlite_1.8.2 foreach_1.5.2 modelr_0.1.9
## [7] bslib_0.4.0 assertthat_0.2.1 highr_0.9
## [10] googlesheets4_1.0.1 cellranger_1.1.0 yaml_2.3.6
## [13] progress_1.2.2 pillar_1.8.1 backports_1.4.1
## [16] glue_1.6.2 digest_0.6.30 RColorBrewer_1.1-3
## [19] rvest_1.0.3 colorspace_2.0-3 plyr_1.8.7
## [22] htmltools_0.5.3 pkgconfig_2.0.3 broom_1.0.1
## [25] haven_2.5.1 scales_1.2.1 tzdb_0.3.0
## [28] googledrive_2.0.0 farver_2.1.1 generics_0.1.3
## [31] ellipsis_0.3.2 cachem_1.0.6 withr_2.5.0
## [34] repr_1.1.4 cli_3.4.1 magrittr_2.0.3
## [37] crayon_1.5.2 readxl_1.4.1 evaluate_0.17
## [40] fs_1.5.2 fansi_1.0.3 doParallel_1.0.17
## [43] xml2_1.3.3 tools_4.2.1 prettyunits_1.1.1
## [46] hms_1.1.2 gargle_1.2.1 lifecycle_1.0.3
## [49] munsell_0.5.0 reprex_2.0.2 compiler_4.2.1
## [52] jquerylib_0.1.4 rlang_1.0.6 grid_4.2.1
## [55] iterators_1.0.14 rstudioapi_0.14 htmlwidgets_1.5.4
## [58] labeling_0.4.2 base64enc_0.1-3 rmarkdown_2.17
## [61] gtable_0.3.1 codetools_0.2-18 reshape_0.8.9
## [64] DBI_1.1.3 reshape2_1.4.4 R6_2.5.1
## [67] lubridate_1.8.0 knitr_1.40 fastmap_1.1.0
## [70] utf8_1.2.2 stringi_1.7.8 parallel_4.2.1
## [73] Rcpp_1.0.9 vctrs_0.4.2 rgl_0.110.2
## [76] dbplyr_2.2.1 tidyselect_1.2.0 xfun_0.33